using System;
using System.Web.Script.Serialization;

namespace MvcFlow
{
    [Serializable]
    public class WorkflowState
    {
        public string   Name            { get; set; }
        public Guid     InstanceId      { get; set; }
        public string   BookmarkName    { get; set; }

        public override string ToString()
        {
            return Name + "," + InstanceId + "," + BookmarkName;
        }

        public static WorkflowState FromString(string input)
        {
            var parts = input.Split(',');

            if ( parts.Length == 3 )
            {
                return new WorkflowState(parts[0],Guid.Parse(parts[1]),parts[2]);
            }

            return null;
        }

        public WorkflowState()
        { }

        public WorkflowState(string name, Guid instanceId, string bookmarkName)
        {
            Name            = name;
            InstanceId      = instanceId;
            BookmarkName    = bookmarkName;
        }
    }

    public static class WorkflowStateExtensions
    {
        public static bool ShouldContinue(this WorkflowState workflowState)
        {
            return !string.IsNullOrWhiteSpace(workflowState.BookmarkName);
        }
    }
}